package org.dromara.germbank.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.constant.SystemConstants;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.germbank.domain.BusOperationsAdvertisement;
import org.dromara.germbank.domain.BusResearchSurveys;
import org.dromara.germbank.domain.bo.BusOperationsAdvertisementBo;
import org.dromara.germbank.domain.bo.BusResearchSurveysBo;
import org.dromara.germbank.domain.vo.BusOperationsAdvertisementVo;
import org.dromara.germbank.domain.vo.BusResearchSurveysVo;
import org.dromara.germbank.mapper.BusResearchSurveysMapper;
import org.dromara.germbank.service.BusResearchSurveysService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 问卷管理 实施类
 *
 * @author congxing
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class BusResearchSurveysServiceImpl implements BusResearchSurveysService {

    private final BusResearchSurveysMapper busResearchSurveysMapper;

    @Override
    public TableDataInfo<BusResearchSurveysVo> queryPageList(BusResearchSurveysBo bo, PageQuery pageQuery) {

        Page<BusResearchSurveysVo> page = busResearchSurveysMapper.queryPageList(pageQuery.build(),this.buildQueryWrapper(bo));
        return TableDataInfo.build(page);
    }

    @Override
    public boolean checkSurveysNameUnique(BusResearchSurveysBo bo) {
        return false;
    }

    @Override
    public int insertSurveys(BusResearchSurveysBo bo) {
        return 0;
    }

    @Override
    public void updateSurveysData(BusResearchSurveysBo bo) {

    }

    @Override
    public void deleteSurveysCodesDataByIds(List<Long> bo) {

    }


    //分页查询条件
    private Wrapper<BusResearchSurveys> buildQueryWrapper(BusResearchSurveysBo bo) {
        return Wrappers.<BusResearchSurveys>lambdaQuery()
            // 逻辑删除字段（固定条件）
            .eq(BusResearchSurveys::getDelFlag, SystemConstants.NORMAL)

            // 调研名称（模糊）
            .like(StringUtils.isNotBlank(bo.getSurveyName()),
                BusResearchSurveys::getSurveyName, bo.getSurveyName())

            // 调研位置（模糊）
            .like(StringUtils.isNotBlank(bo.getLocation()),
                BusResearchSurveys::getLocation, bo.getLocation())

            // 状态（精确）
            .eq(bo.getStatus() != null,
                BusResearchSurveys::getStatus, bo.getStatus())

            // 时间段：startAt ≤ 数据库字段 ≤ endAt
            .ge(bo.getStartAt() != null,
                BusResearchSurveys::getStartAt, bo.getStartAt())
            .le(bo.getEndAt() != null,
                BusResearchSurveys::getEndAt, bo.getEndAt())

            // 排序
            .orderByAsc(BusResearchSurveys::getId);
    }
}
